package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.EcologyHatchMethodConf;
import com.sc.nft.mapper.EcologyHatchMethodConfMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;

/**
 * 生态-熔炼方式主表(sc_ecology_hatch_method_conf)数据DAO
 *
 * @author Sun
 * @description 由 Mybatisplus Code Generator 创建
 * @since 2024-06-07 09:04:10
 */
@Slf4j
@Repository
public class EcologyHatchMethodConfDao extends ServiceImpl<EcologyHatchMethodConfMapper, EcologyHatchMethodConf> {


    public boolean updateById(Long id, Long sort, Boolean status, String methodName, BigDecimal dynamicRewardAmount) {
        LambdaUpdateWrapper<EcologyHatchMethodConf> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(EcologyHatchMethodConf::getId, id);
        wrapper.set(EcologyHatchMethodConf::getStatus, status);
        wrapper.set(EcologyHatchMethodConf::getSort, sort);
        wrapper.set(EcologyHatchMethodConf::getMethodName,methodName);
        wrapper.set(EcologyHatchMethodConf::getDynamicRewardAmount,dynamicRewardAmount);
        return update(new EcologyHatchMethodConf(), wrapper);
    }

    /**
     * 获取熔炼方式列表
     *
     * @param ecologyHatchId
     * @return
     */
    public List<EcologyHatchMethodConf> getListByEcologyHatchId(Long ecologyHatchId, Boolean status) {
        LambdaQueryWrapper<EcologyHatchMethodConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EcologyHatchMethodConf::getEcologyHatchId, ecologyHatchId);
        if (Objects.nonNull(status)) {
            wrapper.eq(EcologyHatchMethodConf::getStatus, status);
        }
        wrapper.orderByDesc(EcologyHatchMethodConf::getSort).orderByDesc(EcologyHatchMethodConf::getId);
        return list(wrapper);
    }

    public List<EcologyHatchMethodConf> getAllList() {
        LambdaQueryWrapper<EcologyHatchMethodConf> wrapper = new LambdaQueryWrapper<>();
        return list(wrapper);
    }
}